package org.liukai.ssh_ems.dao;

import org.hibernate.SessionFactory;
import org.liukai.ssh_ems.entity.po.Emp;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @project ssh_ems
 * @create EmpDao.java 
 * 
 * @author liukai
 * @date 2016/1/13 10:57
 * @detail 
 */
@Repository
public class EmpDao extends HibernateDaoSupport {
    @Resource
    public void setSF(SessionFactory sessionFactory) {
        System.out.println("注入sessionFactory");
        super.setSessionFactory(sessionFactory);
    }

    public List<Emp> queryEmpList() {
        return (List<Emp>) getHibernateTemplate().find("from Emp");
    }

    public void deleteEmp(Emp emp) {
        getHibernateTemplate().delete(emp);
    }

    public void insertEmp(Emp emp) {
        getHibernateTemplate().save(emp);
    }

    public Emp queryEmpById(Integer empId) {
        return getHibernateTemplate().get(Emp.class, empId);
    }

    public void updateEmp(Emp emp) {
        getHibernateTemplate().update(emp);
    }

    public EmpDao() {
        System.out.println("实例化EmpDao");
    }





}


